﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TaskSchedulingSystemForm.Model;
using Common;
using TaskSchedulingSystemForm.Common;

namespace TaskSchedulingSystemForm
{
    public partial class AlterTaskCronRole : Form
    {
        private static TaskModel task;
        private static TaskConfig xmlConfig;
        public AlterTaskCronRole(TaskModel ta, TaskConfig Config)
        {
            InitializeComponent();
            task = ta;
            xmlConfig = Config;
            this.setCronControl1.ReturnCronExpression = GetValidCron;
            this.label1.Text = "要修改的任务："+ta.taskName;
        }
        /// <summary>
        /// 获取有效的cron表达式
        /// </summary>
        /// <param name="cron"></param>
        private void GetValidCron(string cron)
        {
            string filePath = "TaskConfig.xml";
            task.cronExpression = cron;
            LocalCacheFactory.ToFile<TaskConfig>(filePath, xmlConfig);
            DialogResult dr = MessageBox.Show("任务时间规则修改成功！", "提示信息", MessageBoxButtons.OK);
            TSSLog.WrriteXTLog(task, TSSOP.ChangeTaskConfigInfo);
            if (dr == DialogResult.OK)
            {
                this.Close();
            }          
        }
    }
}
